package common;

import java.util.EnumSet;

import javax.servlet.DispatcherType;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration.Dynamic;
import javax.servlet.annotation.HandlesTypes;

import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
@HandlesTypes(WebApplicationInitializer.class)
public class mainApplication implements WebApplicationInitializer {

	@Override
	public void onStartup(ServletContext servletContext) throws ServletException {
		// TODO Auto-generated method stub
		System.out.println("I was Spring");
		AnnotationConfigWebApplicationContext aContext = new AnnotationConfigWebApplicationContext();
		aContext.setServletContext(servletContext);
		aContext.register(mainConfig.class,DBconfig.class,MyFilter.class);
		Dynamic servlet = servletContext.addServlet("springmvc", new DispatcherServlet(aContext));
		servlet.addMapping("*.do");
		servlet.setLoadOnStartup(1);
		javax.servlet.FilterRegistration.Dynamic filter = servletContext.addFilter("utf8", new MyFilter());
		filter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), false, "/*");
	}

}
